package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.entity.Refunds;
import com.chixing.mapper.RefundsMapper;
import com.chixing.service.IRefundsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author smith
 * @since 2025-09-30
 */
@Service
public class RefundsServiceImpl extends ServiceImpl<RefundsMapper, Refunds> implements IRefundsService {

    @Autowired
    private RefundsMapper refundsMapper;


    @Override
    public Result CreateRefundsOrder(Refunds refunds) {

        refunds.setRefundMethod("原路返回");
        refunds.setApplyTime(LocalDateTime.now());
        refunds.setRefundStatus("未退款");

        int rows = refundsMapper.insert(refunds);

        if (rows > 0){
            System.out.println("已经成功创建退款订单");
            return Result.getSuccess(refunds);
        }
        return Result.getFail(null);
    }

    @Override
    public Refunds getPendingOrSuccessRefund(String outRequestNo) {

        QueryWrapper<Refunds> refundsQueryWrapper = new QueryWrapper<>();
        refundsQueryWrapper.eq("out_request_no",outRequestNo);

        Refunds refunds = refundsMapper.selectOne(refundsQueryWrapper);

        return refunds;
    }
}
